package com.集合.Collections类.模拟斗地主;

import java.util.ArrayList;
import java.util.Collections;

public class PokerDemo {
    public static void main(String[] args) {
        ArrayList<String> array = new ArrayList<>();
        //图案数组
        String[] pattern = {"♦", "♣", "♠", "♥"};
        //数字数组
        String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};

        //增强for循环嵌套
        for (String p : pattern) {
            for (String n : numbers) {
                array.add(p + n);
            }
        }
        array.add("大王");
        array.add("小王");

        //洗牌
        Collections.shuffle(array);

        //发牌
        ArrayList<String> firstArray = new ArrayList<>();
        ArrayList<String> secondArray = new ArrayList<>();
        ArrayList<String> thirdArray = new ArrayList<>();
        ArrayList<String> dpArray = new ArrayList<>();

        for (int i = 0; i < array.size(); i++) {
            String poker = array.get(i);
            if (i >= array.size() - 3) {
                dpArray.add(poker);//预留三张底牌
            } else if (i % 3 == 0) {
                firstArray.add(poker);
            } else if (i % 3 == 1) {
                secondArray.add(poker);
            } else if (i % 3 == 2) {
                thirdArray.add(poker);
            }
        }
        //看牌 每个玩家的看牌方式相同，定义一个方法来实现
        lookPoker("张三", firstArray);
        lookPoker("李四", secondArray);
        lookPoker("汤姆", thirdArray);
        lookPoker("底牌", dpArray);

    }

    public static void lookPoker(String name, ArrayList<String> array) {
        System.out.print(name + "的牌是:");
        for (String poker : array) {
            System.out.print(poker + " ");
        }
        System.out.println();
    }
}
